package com.customview.CustomLiner;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author Sandsboy
 * @description:广州皓醒科技有限公司
 * @date :2019/12/11 15:05
 */
public class CustomLiner extends View {
    public CustomLiner(Context context) {
        this(context, null);
    }

    public CustomLiner(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomLiner(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        init();

    }


    Paint mPaint;

    Path mPath;

    private void init() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.BLACK);
        mPath = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPath.setFillType(Path.FillType.EVEN_ODD);
        mPath.addCircle(getWidth() / 2f-30, getHeight() / 8f*1, getHeight() / 8f, Path.Direction.CCW);
        mPath.addCircle(getWidth() / 2f+30, getHeight() / 8f*1, getHeight() / 8f, Path.Direction.CCW);
        canvas.drawPath(mPath, mPaint);


        mPath.reset();
        mPath.setFillType(Path.FillType.WINDING);
        mPath.addCircle(getWidth() / 2f-30, getHeight() /8f*3, getHeight() / 8f, Path.Direction.CCW);
        mPath.addCircle(getWidth() / 2f+30, getHeight() / 8f*3, getHeight() / 8f, Path.Direction.CCW);
        canvas.drawPath(mPath, mPaint);

        mPath.reset();
        mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
        mPath.addCircle(getWidth() / 2f-30, getHeight() / 8f*5, getHeight() / 8f, Path.Direction.CCW);
        mPath.addCircle(getWidth() / 2f+30, getHeight() / 8f*5, getHeight() / 8f, Path.Direction.CCW);
        canvas.drawPath(mPath, mPaint);

        mPath.reset();
        mPath.setFillType(Path.FillType.INVERSE_WINDING);
        mPath.addCircle(getWidth() / 2f-30, getHeight() /8f*7, getHeight() / 8f, Path.Direction.CCW);
        mPath.addCircle(getWidth() /  2f+30,getHeight() / 8f*7, getHeight() / 8f, Path.Direction.CCW);
        canvas.drawPath(mPath, mPaint);
    }
}
